// Created by WXX on 2021/9/15 9:24
#include <iostream>
#include <vector>

using namespace std;

/**
 * 执行用时：4 ms, 在所有 C++ 提交中击败了90.11%的用户
 * 内存消耗：10.8 MB, 在所有 C++ 提交中击败了52.44%的用户
 */
class Solution {
public:

    vector<string> ans;

    vector<string> letterCasePermutation(string s) {
        dfs(s, 0);
        return ans;
    }

    void dfs(string s, int u) {
        if (u == s.size()) {
            ans.push_back(s);
            return;
        }

        int k = u;
        while (k < s.size() && !is_letter(s[k])) k++;

        if (k < s.size()) {
            // s[k]转化为小写
            s[k] = tolower(s[k]);
            dfs(s, k + 1);

            // s[k]转化为大写
            s[k] = toupper(s[k]);
            dfs(s, k + 1);
        } else dfs(s, k);
    }

    static bool is_letter(char c) {
        return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
    }
};

void OutputBasicArray1D(vector<string> nums) {
    cout << "[";
    for (int i = 0; i < nums.size(); i++) {
        cout << nums[i];
        if (i != nums.size() - 1) cout << ", ";
    }
    cout << "]" << endl;
}

int main() {

    OutputBasicArray1D(Solution().letterCasePermutation("a1b2"));

    return 0;
}
